#region License Revision: 0 Last Revised: 6/18/2008 11:00 AM
/******************************************************************************
Copyright (c) Microsoft Corporation.  All rights reserved.


This file is licensed under the Microsoft Public License (Ms-PL). A copy of the Ms-PL should accompany this file. 
If it does not, you can obtain a copy from: 

http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
******************************************************************************/
#endregion // License
using System;
using System.Windows.Browser;
using System.Diagnostics;
using System.Text;
using ScriptInterop;
using System.Globalization;

namespace VIEWS // Virtual Earth Wrapper
{

	/// <summary> Latitude/Longitude object </summary>
	public class VELatLong : JSObject
	{
		/// <summary>String holding JavaScript class name</summary>
		private static string thisClass = "VELatLong";
		
		/// <summary>Get the JavaScript class name</summary>
		/// <returns type="String">The class name used in JavaScript </returns>		
		public override string ClassName
		{
			get { return thisClass; }
		}

		/// <summary>Construct a C# wrapper from a ScriptObject</summary>
		public VELatLong(ScriptObject so) : base(so) { }


		/// <summary>Default constructor picks 0,0</summary>
		public VELatLong()
		{	// Init to somewhere in Kirkland
			ScriptObject = CreateClass(0.0, 0.0);
		}
		
		/// <summary>Initializes a new instance of the VELatLong Class.</summary>
		/// <param name="lat" type="Number">The latitude of a single point on the globe.</param>
		/// <param name="lng" type="Number">The longitude of a single point on the globe.</param>
		public VELatLong(double lat, double lng)
		{ ScriptObject = CreateClass(lat, lng); }
		
		/// <summary>Initializes a new instance of the VELatLong Class.</summary>
		/// <param name="lat" type="Number">The latitude of a single point on the globe.</param>
		/// <param name="lng" type="Number">The longitude of a single point on the globe.</param>
		/// <param name="alt" type="Number">The altitude of a single point on the globe.</param>
		public VELatLong(double lat, double lng, double alt)
		{ ScriptObject = CreateClass(lat, lng, alt); }
		
		/// <summary>Initializes a new instance of the VELatLong Class.</summary>
		/// <param name="lat" type="Number">The latitude of a single point on the globe.</param>
		/// <param name="lng" type="Number">The longitude of a single point on the globe.</param>
		/// <param name="alt" type="Number">The altitude of a single point on the globe.</param>
		/// <param name="altMode" type="VEAltitudeMode">A VEAltitudeMode Enumeration (string) value representing the mode in which an altitude is represented.</param>
		public VELatLong(double lat, double lng, double alt, VEAltitudeMode altMode)
		{ ScriptObject = CreateClass(lat, lng, alt, ScriptEnumConverter.ToString(altMode)); }

		/// <summary>Specifies the latitude of a single point on the globe.</summary>		
		public double Latitude
		{
			get { return GetProperty<double>("Latitude"); }
			set { SetProperty("Latitude", value); }
		}
		
		/// <summary>Specifies the longitude of a single point on the globe.</summary>		
		public double Longitude
		{
			get { return GetProperty<double>("Longitude"); }
			set { SetProperty("Longitude", value); }
		}
		
		/// <summary>Specifies the altitude of a single point on the globe, meaning depends on altitude mode</summary>		
		public double Altitude
		{
			get { return GetProperty<double>("Altitude"); }
			set { SetProperty("Altitude", value); }
		}
		
		/// <summary>Specifies the mode in which an altitude is represented.</summary>		
		public VEAltitudeMode AltitudeMode
		{
			get { return ScriptEnumConverter.ToAltitudeMode(GetProperty<string>("AltitudeMode")); }
			set { SetProperty("AltitudeMode", ScriptEnumConverter.ToString(value)); }
		}

		public override string ToString()
		{
			StringBuilder bld = new StringBuilder();
			bld.Append(Latitude.ToString("####.###", CultureInfo.InvariantCulture));
			bld.Append(", ");
            bld.Append(Longitude.ToString("####.###", CultureInfo.InvariantCulture));
			if (Altitude != 0)
			{
				bld.Append(": alt-");
                bld.Append(Altitude.ToString("#####.#", CultureInfo.InvariantCulture));
				bld.Append("m: ");
				bld.Append(AltitudeMode);
			}
			return bld.ToString();
		}
		/// <summary>Initializes a new instance of the VELatLong Class.</summary>
		/// <param name="altitude" type="Number">The altitude of a single point on the globe.</param>
		/// <param name="altitudeMode" type="VEAltitudeMode">A VEAltitudeMode Enumeration value representing the mode in which an altitude is represented.</param>
		public void SetAltitude(double altitude, string mode)
		{
			Invoke("SetAltitude", altitude, mode);
		}

        /// <summary>
        /// Gets a latitude and longitude of 0,0.
        /// </summary>
        static private VELatLong zero = null;
        static public VELatLong Zero
        {
            get
            {
                if (zero == null)
                {
                    zero = new VELatLong(0.0, 0.0);
                }
                return zero;
            }
        }
	};
	
}
